import requests
import os
import json
from config.configs import DATA_PATH, HEADER
from tools.clean_datas import jw_clean_settlements
from tools.mongo_tool import MongoDbLink


def upload_wf_settlement():
    """workflow结算上传"""
    url = "https://workflow-api-dev.geehoop.com/api/backend/settlement/upload"
    file_path = os.path.join(DATA_PATH, 'wf_settlement_upload.xlsx')
    file = {'file': open(file_path, mode='rb')}
    r = requests.post(url=url, headers=HEADER, files=file)
    result = json.loads(r.text)
    new_url = "https://workflow-api-dev.geehoop.com/api/backend/settlement"
    data = {"settlementMethod": "手动上传", "settlementList": result['data']}
    rr = requests.post(url=new_url, headers=HEADER, json=data)
    print(rr.text)


def upload_jw_settlement():
    """集物结算上传"""
    jw_clean_settlements()
    url = 'https://test.geehoop.com/api/backend/settlement'
    header = {"Authorization": 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1MGE0YTg2ODNmOTE1YzM4ZDE4YzY0MCIsImlhdCI6MTcwNDE2NTA0NCwiZXhwIjoxNzA0NzY5ODQ0fQ.bkL8vWzLLxnjtK0lJjYjZSiaRjOcR7WpnKtyYbwc3Q0'}
    file = os.path.join(DATA_PATH, 'jw_settlement_upload.xlsx')
    r = requests.post(url=url, headers=header, data=file)
    print(r.text)



# spus = ["DX9012-300", "NJ3NP55A", "CT8529-170", "DZ5485-701", "DZ4129-102", "IA3448-海外版", "M1906RB", "DD1503-119",
#         "416394", "DD1391-600", "FY7755", "AT8240-104", "FX5502", "CW2288-111", "DD8959-100", "1JM01248_001", "10061M",
#         "FU7712", "EG4959", "B75807", "BV1358-001", "B75806", "10061W"]
# price = [405.75, 870, 691.63, 682.41, 442.6, 150, 604.67, 433.03, 1033.12, 350.42, 277.99, 516.41, 224.12, 464.73,
#          473.13, 230, 538.69, 201.35, 354.67, 431.65, 577.44, 438.65, 532.14]
# art = []
# for s in spus:
#     art.append(articleNumber_to_spuId(s))
# print(art)
# for spu in range(len(art)):
#     alpha.stocks.update_many({"merchantCode": "8565","warehouseType": "common","spuId": art[spu]}, {"$set":{"costUnitPrice": price[spu]*100}})

